package com.tbit.uqbike.client.controller;

import com.tbit.uqbike.client.constant.ResponseCode;
import com.tbit.uqbike.client.exception.BaseException;
import com.tbit.uqbike.client.pojo.BrandConfig;
import com.tbit.uqbike.client.pojo.User;
import com.tbit.uqbike.client.service.BrandConfigService;
import com.tbit.uqbike.client.service.TokenService;
import com.tbit.uqbike.client.util.Assert;
import com.tbit.uqbike.client.util.OutputUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 品牌配置
 *
 * @Author: chen
 * @Description: 品牌配置
 * @Date: 创建于 10:41 2021/1/6
 */
@Controller
@RequestMapping("/brandConfig")
public class BrandConfigController {
    @Autowired
    private BrandConfigService brandConfigService;
    @Autowired
    private TokenService tokenService;


    /**
     * 通过品牌id获取
     *
     * @param token     令牌
     * @param accountId 帐户id
     * @param response  响应
     * @ignoreParams request
     */
    @RequestMapping("/getByAccountId")
    public void getByImageId(String token, Integer accountId, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = new HashMap<String, Object>();

        try {
            /* 校验 */
            Assert.notNull(accountId, "-10001", "品牌id不能为空");
            if (token != null) {
                User user = tokenService.getUser(token);
            }

            BrandConfig brandConfig = brandConfigService.getByAccountId(accountId);

            map.put(ResponseCode.RET, ResponseCode.SUCC);
            map.put(ResponseCode.DATA, brandConfig);
        } catch (BaseException e) {
            ResponseCode.printException(map, e, request);
        }
        OutputUtil.renderText(request, response, map);
    }

}
